﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using 工作流XMLDomain修改工具.Codes;

namespace 工作流XMLDomain修改工具
{
    public partial class 主界面 : Form
    {
        public static DbServer DbSvr = null;

        public 主界面()
        {
            InitializeComponent();
        }

        private void initDbSvr()
        {
            DbSvr = new DbServer(this.combServerAddress.Text,
                this.txtDbUser.Text,
                this.txtDbPwd.Text,
                this.combDb.Text);
        }

        private void btnTestConn_Click(object sender, EventArgs e)
        {
            initDbSvr();

            if (DbSvr.TestConnection())
            {
                MessageBox.Show("连接成功。");
            }
            else
            {
                MessageBox.Show("连接失败。");
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string keywords = txtKeywords.Text.Trim();
            int count = 20;
            int.TryParse(txtReadCount.Text, out count);

            initDbSvr();

            if (DbSvr.TestConnection() == false)
            {
                MessageBox.Show("连接失败。");
                return;
            }

            if (string.IsNullOrEmpty(keywords))
            {
                MessageBox.Show("查询信息不能为空。");
                return;
            }

            dataGridView1.AutoGenerateColumns = true;
            dataGridView1.DataSource = Business.GetDataTable(keywords, count);
        }

        private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            string processGUID = (sender as DataGridView).Rows[e.RowIndex].Cells["ProcessGUID"].Value.ToString();
            using (XML编辑界面 ui = new XML编辑界面(new Guid(processGUID)))
            {
                ui.ShowDialog();
            }
        }
    }
}
